<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Service Model
 *
 * @package     VisualQ Local System
 * @author      CSU OJT Students '10 - '11 (Michael Roland B. Martin)
 * @copyright   Copyright (c) 2010 - 2011, Bitstop Network Services, Inc.
 * @version     1.0 January 27, 2011
 */

class Service_model extends Model {

    function Service_model() {
        parent::Model();
        $this->load->database();

        $this->CI =& get_instance();
    }

    /**
     * Get a service data
     *
     * Used by:
     *      ajax/get_closing_codes/
     *
     * @param	array
     *      si              :   service id
     * @return  object
     *      query           :   query result
     */
    function get_service_details($si)
    {
        $query = $this->db->get_where('services', array('id' => $si));

        return $query;
    }

    /**
     * Get a agent service
     *
     * Used by:
     *      ajax/agents_grid/
     *
     * @param	array
     *      id              :   account id
     * @return  object
     *      query           :   query result
     */
    function get_agent_services($id)
    {
        $this->db->join('services', 'accounts_services.service_id = services.id');
        $this->db->where('account_id', $id);
        return $this->db->get('accounts_services');
    }

    /**
     * Get all services that can be rendered by an agent
     *
     * Used by:
     *      ajax/agents_grid/
     *      ajax/get_latest_numbers/
     *
     * @return  object
     *      query           :   the query result
     */
    function get_available_services()
    {
        $this->db->distinct();
        $this->db->select('service_id, services.id, title, prefix, closing_codes');
        $this->db->join('services', 'accounts_services.service_id = services.id', 'left');

        return $this->db->get('accounts_services');
    }

}

/* End of file service_model.php */
/* Location: ./system/application/model/service_model.php */